#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "esp_log.h"
#include "esp_event.h"
#include "driver/i2c.h"
#include "driver/gpio.h"

// FreeRTOS includes
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"

// Project includes
#include "Dart_Events.h"
#include "firmware.h"
#include "power.h"
#include "LED.h"

// Including OneMeesage
#include "om.hpp"

// Including ESP-NOW
#include "esp_mac.h"
#include "espnow.h"

#define DEVICE_NUMBER 15

enum omEvents_m{
    requestPingData,
    requestOperationData,
    responseStatusData,
    responseOperationData,
    omReserved,
};

// enum omChannels_m{
//     OM_PUBLIC,
//     OM_PRIVATE,
//     OM_RESERVED,
// };

enum state_m{
    IDLE,
    IDLE_ACTIVATED,
    ACTIVATED,
    // RESERVED
};

enum operation_m{
    OPERATION_PWR,
    OPERATION_OTA
};

enum pwr_m{
    PWR_ON,
    PWR_OFF
};

enum ota_m{
    OTA_TRIGGGER,
    OTA_ENABLE,
    OTA_DISABLE
};

enum errorCode_m{
    OPERATION_OK,
    OPERATION_FAIL_WIFI,
    OPERATION_FAIL_HARWARE,
    OPERATION_FAIL_BATTERY,
    OPERATION_FAIL_TIMEOUT,
    OPERATION_FAIL_RESERVED
};

struct stdMsg_t
{
    // char topic;
    uint8_t selfMAC[6];
    uint8_t destMAC[6];
};

struct requestPing_t
{
    stdMsg_t stdMsg;
    uint8_t connectedDevice;
    char deviceMAC[DEVICE_NUMBER][6];
};

struct requestOperation_t
{
    stdMsg_t stdMsg;
    uint16_t session;
    uint16_t operation;
    int operationParam;
};

struct responseStatus_t
{
    stdMsg_t stdMsg;
    uint16_t batteryVoltage;
    uint8_t batteryLevel;
    bool boostState;
    bool chargeState;
    float chargeCurrent;
    float chargeVoltage;
};

struct responseOperation_t
{
    stdMsg_t stdMsg;
    uint16_t session;
    uint16_t errorCode;
};


